<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'用户管理',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>用户名称</span></td>
				<td class="screen-n">
					<input type="text" id="s_userName" class="screen-input"  onkeydown="pms.kd13('initList')" style="width:200px;">
				</td>
				<td class="screen-n"><span>登录帐号</span></td>
				<td class="screen-n">
					<input type="text" id="s_loginName" class="screen-input"  onkeydown="pms.kd13('initList')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initList()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm');initList();" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    
    
    <div id="toolbar" style="display: none;">
    
    	<table>
		<tr>
			<se:hasPermissions actCode="DELETE" >
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_delete',plain:true" onclick="deleteRecords();">删除</a>
			</td>
			</se:hasPermissions>
			<se:hasPermissions actCode="MAINTAIN" >
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-lock_open',plain:true" onclick="changenStatusBat('isValid',1);">启用</a>
			</td>
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-lock',plain:true" onclick="changenStatusBat('isValid',2);">锁定</a>
			</td>
			</se:hasPermissions>
		</tr>
	</table>
    
    </div>
    
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>
<script>
function openAddWindow(){
	$.pmsDialog({
		id:"w_form",
		title:'新增',
		method:'post',
		href:'<c:url value="/views/jsp/customer/user/form.jsp"/>',
		width:600,
		height:600
	});
}

// 批量属性
function changenStatusBat(type,value){
	var rows = tbl.getSelectedData();
	if(rows.length>0){
		if(confirm("确定批量操作?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].userId);
			}

			var userIdList = ids.toString();
			
			var param = {};
			param[type] = value;
			param["userIdList"] = userIdList;
			
			$.pmsAjax({
				url:'<c:url value="/user/updateEmCUserBat.do"/>',
				data:param,
				success:function(data){
					if(data.code==200){
						alertShow("批处理成功");
						initList();
					}else{
						alertError(data.resultMessage);
					}
				}
			}); 
		}
	}else{
		alertError('请选择操作记录');
	}
}

function changePwd(userId){
	var param = {};
	param["loginPwd"] = "abc@123456";
	param["userId"] = userId;
	if(confirm("确定操作该记录?")){
		$.pmsAjax({
			url:'<c:url value="/user/updateEmCUser.do"/>',
			data:param,
			success:function(data){
				if(data.code==200){
					initList();
				}else{
					alertError(data.resultMessage);
				}
			}
		}); 
	}
}
// 单个属性
function changenStatus(userId,type,value){
	var param = {};
	param[type] = value;
	param["userId"] = userId;
	if(confirm("确定操作该记录?")){
		$.pmsAjax({
			url:'<c:url value="/user/updateEmCUser.do"/>',
			data:param,
			success:function(data){
				if(data.code==200){
					initList();
				}else{
					alertError(data.resultMessage);
				}
			}
		}); 
	}
}

function openUpdateWindow(userId){
	var params = {"userId":userId}
	$.pmsDialog({
		id:"w_form",
		title:'修改',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/user/form.jsp"/>',
		width:600,
		height:600
	});
}

function deleteRecords(){
	var rows = tbl.getSelectedData();
	if(rows.length>0){
		if(confirm("确定批量删除?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].userId);
			}
			var userIdList = ids.toString();
			var param = {"userIdList":userIdList};
			$.pmsAjax({
				url:'<c:url value="/user/deleteMultipleEmCUser.do"/>',
				data:param,
				success:function(data){
					if(data.code==200){
						alertShow("删除批量成功");
						initList();
					}else{
						alertError(data.resultMessage);
					}
				}
			});
		}
	}else{
		alertError('请选择操作记录');
	}
	
}

function deleteRecord(userId,i){
	if(confirm("确定删除记录?")){
		var param = {"userId":userId};
		$.pmsAjax({
			url:'<c:url value="/user/deleteEmCUser.do"/>',
			data:param,
			success:function(data){
				if(data.code==200){
					alertShow("删除记录成功");
					initList();
				}else{
					alertError(data.resultMessage);
				}
			}
		});
	}
}

var tbl;
$(function(){
	initList();
});
function getParams(){
	var queryParamss = {
			"userName":$("#s_userName").val(),
			"loginName":$('#s_loginName').val()
	    };
    return queryParamss;
}
function initList(){
	tbl = $('#tableGrid').pDataGrid({
		toolbar : '#toolbar',
		 columns:[[
		          {field:'ck',checkbox:true},
		          {field:'loginName',title:'登录名称',width:'80',sortable:true},
				  {field:'userName',title:'用户名称',width:'200',sortable:true},
				  {field:'mobilePhone',title:'联系手机',width:'100',sortable:true},
				  {field:'telePhone',title:'联系电话',width:'100',sortable:true},
				  {field:'address',title:'联系地址',width:'200',sortable:true},
				  {field:'isValid',title:'用户状态',width:'60',sortable:true,align:'center',
					  formatter:function(value,row){
						  var str = '';
							switch(value){
							case 0:
								str = '刚注册';
								break;
							case 1:
								str = '已审核';
								break;
							case 2:
								str = '被锁定';
								break;
							default:
								str = '刚注册';
								break;
							}
							return str;
						}  
				  },
				  {
						title : '操作',
						field : 'action',
						width : '120',
						align : 'center',
						formatter : function(value, row, index) {
							var str = '';
							<se:hasPermissions actCode="UPDATE" >
								str += ' <img class="iconImg ext-icon-note_edit" title="编辑" onclick="openUpdateWindow('+row.userId+');"/>';
							</se:hasPermissions>
							<se:hasPermissions actCode="DELETE" >
								str += ' <img class="iconImg ext-icon-note_delete" title="删除" onclick="deleteRecord('+row.userId+',' + index + ');"/>';
							</se:hasPermissions>
							<se:hasPermissions actCode="MAINTAIN" >
								str += ' <img class="iconImg ext-icon-bullet_key" title="重置密码为abc@123456" onclick="changePwd('+row.userId+');"/>';
								str += ' <img class="iconImg ext-icon-lock" title="锁定" onclick="changenStatus('+row.userId+',\'isValid\',' + 2 + ');"/>';
							</se:hasPermissions>
							<se:hasPermissions actCode="APPROVE" >
								str += ' <img class="iconImg ext-icon-lock_open" title="审核" onclick="changenStatus('+row.userId+',\'isValid\',' + 1 + ');"/>';
							</se:hasPermissions>
								return str;
						}
					} 
				  ]
			  ],
		    url:'<c:url value="/user/searchPageEmCUser.do"/>',  
		    pagination:true,
		    pageSize:30,
		    fitColumns:false,
		    singleSelect:false,
		    queryParams:getParams(),
		    completeCallback:function(data){
				if(data.resultCode == "100"){
					alertError(data.errorMsg);
				} 
			},
			onDblClickRow:function(index,row){
				openUpdateWindow(row.userId);
			}
	}); 
	
}

//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/user/searchPageEmCUserExcel.do"/>',getParams());
} 	
</script>
